<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/28 0028
 * Time: 上午 9:22
 */

namespace app\sports_admin\model;


use think\Model;
use traits\model\SoftDelete;

class SportsGame extends Model
{
    use SoftDelete;
    protected $table = 'sports_game';

    protected $autoWriteTimestamp = true;

    protected $pk = 'id';


    /**
     * 运动游戏列表
     * @param array $info 信息
     */
    public static function sportsGameList($info)
    {
        $rows = self::field('id,images,title,age_group,video,target')
            ->where(function ($query)use($info){
                if($info['searchName']){
                    $query->where('title','like',"%{$info['searchName']}%");
                }
            })->order($info['sort'],$info['sortOrder'])
            ->page($info['page'])->limit($info['rows'])->select();
        $count = self::where(function ($query)use($info){
            if($info['searchName']){
                $query->where('title','like',"%{$info['searchName']}%");
            }
        })->order($info['sort'],$info['sortOrder'])->count();
        return ['total'=>$count,'rows'=>$rows];
    }
}